import type { Directive, DirectiveBinding } from 'vue';
import { useHasPermi } from '@/hooks/useHasPermi';

export const hasPermi: Directive = {
  mounted(el: HTMLElement, binding: DirectiveBinding) {
    const hasPermi = useHasPermi();
    const value = binding.value;

    if (!hasPermi(value)) {
      el.parentNode?.removeChild(el);
    }
  },
};
